package com.zr.d_c.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.d_c.dao.EvaluateDao;
import com.zr.d_c.model.Evaluate;
import com.zr.d_c.util.JDBCUtil;

public class EvaluateDaoImpl implements EvaluateDao{

	@Override
	public Evaluate selectEvaluateByOid(int oid) {
		Evaluate evaluate = new Evaluate();
		Connection con = JDBCUtil.getConnection();
		StringBuffer sql = new StringBuffer("select * from d_cevaluate where oid = ?");
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, oid);
			ResultSet rs = pst.executeQuery();
			if(rs.next()){
				evaluate.setEid(rs.getInt("eid"));
				evaluate.setEtext(rs.getString("etext"));
				evaluate.setEcreatetime(rs.getString("ecreatetime"));
				evaluate.setEisdelete(rs.getInt("eisdelete"));
				evaluate.setOid(rs.getInt("oid"));
			}
			con.close();
			pst.close();
			rs.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return evaluate;
	}

	@Override
	public int insertEvaluateByOid(Evaluate ev, int oid) {
		// TODO Auto-generated method stub
		int flag = 0;
		Connection con = null;
		PreparedStatement pst = null;
		
		StringBuffer sql = new StringBuffer("insert into d_cevaluate (etext,eisdelete,ecreatetime,oid) values(?,?,?,?)");
		try {
			con = JDBCUtil.getConnection();
			pst = con.prepareStatement(sql.toString());
			pst.setString(1, ev.getEtext());
			pst.setInt(2, ev.getEisdelete());
			pst.setString(3, ev.getEcreatetime());
			pst.setInt(4, oid);
			int i = pst.executeUpdate();
			if(i > 0){
				flag = 1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			JDBCUtil.closeJDBC(pst, con);
		}
		return flag;
	}

}
